package com.ym.medical.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ym.core.utils.tkmybatis.BaseSVImpl;
import com.ym.medical.dao.AddressGroupDao;
import com.ym.medical.dao.PatientDetailDao;
import com.ym.medical.dao.UserDao;
import com.ym.medical.domain.entity.AddressGroupEntity;
import com.ym.medical.domain.entity.UserEntity;
import com.ym.medical.domain.vo.AddressBookPacketDataVo;
import com.ym.medical.domain.vo.MyPatientVO;
import com.ym.medical.enums.AddressGroupAlgTypeEnum;
import com.ym.medical.enums.SystemGroupEnum;
import com.ym.medical.service.IAddressGroupSV;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * ComputerName:LAPTOP-6GI4HOI6
 * Author:625
 * Date: 2019-05-22
 * Time: 14:14:22
 * 服务实现类
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class AddressGroupSVImpl extends BaseSVImpl<AddressGroupEntity, AddressGroupDao> implements IAddressGroupSV {

    @Autowired
    private PatientDetailDao patientDetailDao;

    @Autowired
    private UserDao userDao;

    @Override
    public List<AddressBookPacketDataVo> getAddressBookPacketData(Long id, String type) {

        return mapper.getAddressBookPacketData(id, type);
    }

    /***
     *
     * @param pageNo  页码
     * @param limit   每页条数
     * @param groupId  分组id
     * @param userId  当前用户id
     * @return
     */
    @Override
    public PageInfo<MyPatientVO> getGroupFriends(
            int pageNo, int limit, Long groupId,
            Long userId, String keyword) {
        PageHelper.startPage(pageNo, limit);
        List<MyPatientVO> patientDetails = patientDetailDao.getGroupFriends(groupId, userId, keyword);
        PageInfo<MyPatientVO> pageInfo = new PageInfo<>(patientDetails);
        return pageInfo;
    }

    /***
     * 我的粉丝列表查询
     * @param pageNo 页码
     * @param limit 每页条数
     * @param groupId 分组id
     * @param userId 用户id
     * @param keyword 搜索关键字
     * @return
     */
    @Override
    public PageInfo<UserEntity> getGroupFan(int pageNo, int limit, Long groupId, Long userId, String keyword) {
        PageHelper.startPage(pageNo, limit);
        List<UserEntity> userList = userDao.getGroupFan(groupId, userId, keyword);
        PageInfo<UserEntity> userPageInfo = new PageInfo<>(userList);
        return userPageInfo;
    }

    /**
     * 查询是否是提别关注用户
     *
     * @param currUser  当前用户id
     * @param patientId 患者id
     * @return
     */
    @Override
    public AddressGroupEntity getAttentionPatient(Long currUser, Long patientId) {
        AddressGroupEntity addressGroup = mapper.getAttentionPatient(currUser, patientId);
        return addressGroup;
    }

    /***
     * 安userId查询
     * @param pageNum
     * @param pageSize
     * @param groupId
     * @param userId
     * @param keyword
     * @return
     */
    @Override
    public PageInfo<MyPatientVO> getMyGroupFan(int pageNum, int pageSize, Long groupId, Long userId, String keyword) {
        PageHelper.startPage(pageNum, pageSize);
       List<MyPatientVO>  list = patientDetailDao.getMyGroupFan(groupId,userId,keyword);
        return new PageInfo<>(list);
    }

    /***
     * 我的粉丝
     * @param pageNum
     * @param pageSize
     * @param groupId
     * @param userId
     * @param keyword
     * @return
     */
    @Override
    public PageInfo<MyPatientVO> getFan(int pageNum, int pageSize, Long groupId, Long userId, String keyword) {
        PageHelper.startPage(pageNum, pageSize);
        List<MyPatientVO> list = patientDetailDao.getFan(
                userId,keyword, AddressGroupAlgTypeEnum.System.getKey(), SystemGroupEnum.PATIENT.FANS.getName());
        return  new PageInfo<>(list);
    }

    /***
     * 全部患者检索
     * @param pageNum
     * @param pageSize
     * @param userId
     * @param keyword
     * @return
     */
    @Override
    public PageInfo<MyPatientVO> selectAll(int pageNum, int pageSize, Long userId, String keyword) {
        PageHelper.startPage(pageNum, pageSize);
        List<MyPatientVO> list = patientDetailDao.selectPatients(
                userId,keyword, AddressGroupAlgTypeEnum.System.getKey(), SystemGroupEnum.PATIENT.INQUIRY.getName());
        return  new PageInfo<>(list);
    }

    /**
     * 所有分组患者列表
     * @param pageNum
     * @param pageSize
     * @param currId
     * @param keyword
     * @return
     */
    @Override
    public PageInfo<MyPatientVO> followPatientList(int pageNum, int pageSize, Long currId, String keyword) {
        PageHelper.startPage(pageNum, pageSize);
        List<MyPatientVO> list = patientDetailDao.followPatientList(currId,keyword);
        return new PageInfo<>(list);
    }
}
